'use strict';
const cloud = require('wx-server-sdk');
const TcbRouter = require('tcb-router');

cloud.init({
    env: 'qiqi-0gyvs18n9b62dabc'
})
const db = cloud.database();
const _ = db.command;

exports.main = async (event, context) => {
    const app = new TcbRouter({ event });
    app.use(async (ctx, next) => {
        await next();
    });
    app.router('getUnmark', async (ctx, next) => {
        const processor = require('./getUnmark.js');
        ctx.body = processor.main(ctx, db);
    });

    app.router('getOssUploadKey', async (ctx, next) => {
        const processor = require('./util/aliutil.js');
        ctx.body = processor.getOssUploadKey(ctx, db);
    });

    app.router('productDivideApi', async (ctx, next) => {
        const processor = require('./util/aliutil.js');
        ctx.body = processor.productDivideApi(ctx, db);
    });

    app.router('hdProductDivideApi', async (ctx, next) => {
        const processor = require('./util/aliutil.js');
        ctx.body = processor.hdProductDivideApi(ctx, db);
    });

    return app.serve();
};
